package com.xp.basic.heima.nio.netty.simpledemo.simple;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

import java.net.InetSocketAddress;

public class TestNettyClientDemo {

    public static void main(String[] args) throws InterruptedException {
        new Bootstrap()
                //代表的是多线程 + selector
                .group(new NioEventLoopGroup())
                //设置实现类
                .channel(NioSocketChannel.class)
                //处理handle
                .handler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel sc) throws Exception {
                        sc.pipeline().addLast(new StringEncoder());
                    }
                })
                .connect(new InetSocketAddress(8080))
                .sync()
                .channel()
                //带flush 是直接将发送
                .writeAndFlush("测试");
    }
}
